<?php

namespace App\Admin\Tools\Task;

use App\Models\AdminUsersModel;
use App\Models\TaskTransferRecordModel;
use Encore\Admin\Grid\Tools\AbstractTool;

class TaskTransferTool extends AbstractTool
{
    private int $id;
    private string $name;

    public function __construct(int $id, string $name)
    {
        $this->id = $id;
        $this->name = $name;
    }

    /**
     * @inheritDoc
     */
    public function render()
    {
        $admin = AdminUsersModel::query()
            ->leftJoin('admin_users_related', 'admin_users_related.user_id', '=', 'admin_users.id')
            ->where('main_id', 0)
            ->where('user_id', '!=', 1)
            ->where('user_id', '!=',USERID)
            ->pluck('name', 'user_id');

        $record = TaskTransferRecordModel::query()
            ->where('task_id', $this->id)
            ->get()->toArray();

        return view('task.transfer', [
            'id' => $this->id,
            'data' => $admin,
            'record' => $record,
            'name' => $this->name
        ]);
    }
}
